package com.lanou3g.util;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;

public class Main {
    public static void main(String[] args) {
        //创建出图片的框
        BufferedImage image =new BufferedImage(300,150,BufferedImage.TYPE_INT_RGB);
        //使用画笔 进行 绘制图片
        Graphics2D graphics = (Graphics2D)image.getGraphics();
        //绘制背景
        graphics.setColor(new Color(255,255,255));
        graphics.fillRect(0,0,300,150);
        //绘制文字
        graphics.setColor(new Color(34,213,123));
        //绘制字符串时,横坐标是字符串左边
        //纵坐标指的是基线的纵坐标
        graphics.setFont(new Font(null,3,25));
        graphics.drawString("pP",0,50);

        graphics.setColor(Color.white);
        graphics.drawLine(0,0,300,150);

        File file =new File("aa.jpg");
        try {
            OutputStream os= new FileOutputStream("aa.jpg");
            ImageIO.write(image,"JPEG",os);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
